using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HourglassSystem
{
    public class TimeLineReactant : MonoBehaviour//todo: interface
    {
        private BoxCollider2D _BC2D;
        private ItemType _ItemType;
        public int _timeLineCode;
        private List<TimeLineReactant> _reactantPool;

        private void Awake()
        {
            _BC2D = GetComponent<BoxCollider2D>();
        }

        private void Start()
        {

        }

        private void Update()
        {

        }

        public void INI_TLReactant(int timeLineCode)
        {
            _timeLineCode = timeLineCode;
            _BC2D.isTrigger = true;
        }

        public void TimeLineSwitchIn()
        {
            _BC2D.isTrigger = false;
        }

        public void TimeLineSwitchOut()
        {
            _BC2D.isTrigger = true;
        }

        private void OnTriggerEnter2D(Collider2D collision)
        {
            //Debug.Log(collision.gameObject.name + " enter");
            TimeLineReactant reactant = collision.gameObject.GetComponent<TimeLineReactant>();
            if (reactant != null)
            {
                _reactantPool.Add(reactant);
            }
        }

        private void OnTriggerExit2D(Collider2D collision)
        {
            //Debug.Log(collision.gameObject.name + " exit");
            TimeLineReactant reactant = collision.gameObject.GetComponent<TimeLineReactant>();
            if (reactant != null)
            {
                _reactantPool.Remove(reactant);
            }
        }
    }
}
